" Some settings have to be done here
set encoding=utf-8
scriptencoding utf-8
set secure
set exrc

" Detect which device we're using to apply device-specific settings.
let g:vimdir = expand('<sfile>:p:h')
if filereadable(g:vimdir . '/.iambiglaptop')
    let g:device = 'biglaptop'
    let g:mobile = 0
elseif filereadable(g:vimdir . '/.iamsmalllaptop')
    let g:device = 'smalllaptop'
    let g:mobile = 0
elseif filereadable(g:vimdir . '/.iamphone')
    let g:device = 'phone'
    let g:mobile = 1
else
    let g:device = 'unknown'
    let g:mobile = 0
endif

" Plugins
call plug#begin(g:vimdir.'/plug')
Plug 'airblade/vim-gitgutter'
Plug 'ap/vim-css-color'
Plug 'aperezdc/vim-template'
    let g:templates_directory = [g:vimdir .. '/templates']
    let g:templates_global_name_prefix = 'template-'
    let g:templates_name_prefix = '.vim-template-'
Plug 'bignimbus/pop-punk.vim'
Plug 'easymotion/vim-easymotion'
    map <silent> ; <plug>(easymotion-prefix)
Plug 'editorconfig/editorconfig-vim'
Plug 'farmergreg/vim-lastplace'
Plug 'junegunn/vim-easy-align'
    nmap ga <plug>(EasyAlign)
    xmap ga <plug>(EasyAlign)
Plug 'lervag/vimtex'
    let g:vimtex_quickfix_mode = 0
Plug 'lucasprag/simpleblack'
Plug 'manicmaniac/coconut.vim'
Plug 'markonm/traces.vim'
" Plug 'mattn/vim-lsp-settings'
"     let g:lsp_settings = {
"                 \   'efm-langserver': {'disable': 1}
"                 \}
Plug 'matze/vim-move'
    let g:move_key_modifier = 'C'
Plug 'pbrisbin/vim-mkdir'
Plug 'prabirshrestha/async.vim'
" Plug 'prabirshrestha/vim-lsp'
"     set omnifunc=lsp#complete
"     let g:lsp_diagnostics_echo_cursor = 1
"     let g:lsp_semantic_enabled = 1
Plug 'Raimondi/delimitMate'
    let delimitMate_expand_cr    = 2
    let delimitMate_expand_space = 1
Plug 'rhysd/clever-f.vim'
Plug 'sheerun/vim-polyglot'
    let g:polyglot_disabled = ['tex', 'latex', 'html', 'java']
Plug 'svermeulen/vim-easyclip'
    let g:EasyClipAutoFormat = 1
    let g:EasyClipShareYanks = 1
    let g:EasyClipAlwaysMoveCursorToEndOfPaste = 1
    let g:EasyClipPreserveCursorPositionAfterYank = 1
    nmap M m$
    nmap <silent> gs <plug>SubstituteOverMotionMap
    nmap gss <plug>SubstituteLine
    xmap gs <plug>XEasyClipPaste
Plug 'tommcdo/vim-exchange'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-endwise'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-sensible'
Plug 'tpope/vim-surround'
Plug 'w0rp/ale'
    let g:ale_echo_msg_format      = '(%linter%) [%severity%% code%] %s'
    let g:ale_list_window_size     = 5
    let g:ale_lint_on_insert_leave = 0
    let g:ale_lint_on_text_changed = 0
    let g:ale_sign_error           = 'EE'
    let g:ale_sign_info            = 'ii'
    let g:ale_sign_style_error     = 'se'
    let g:ale_sign_style_warning   = 'sw'
    let g:ale_sign_warning         = 'WW'
    let g:ale_linters = {
                \   'cs':      ['mcs'],
                \   'dart':    ['language_server'],
                \   'haskell': ['ghc', 'hlint'],
                \   'html':    [],
                \}
    let g:ale_fixers = {
                \   'dart':       ['dartfmt'],
                \   'haskell':    ['hlint'],
                \   'nim':        ['nimpretty'],
                \   'python':     ['black', 'isort'],
                \   'rust':       ['cargo', 'rustc'],
                \}
    " let g:ale_javascript_prettier_options = ''
    "             \   . ' --trailing-comma es5'
    "             \   . ' --html-whitespace ignore'
    let g:ale_python_mypy_options = '--ignore-missing-imports'
    if g:mobile
        let g:ale_set_highlights = 0
    endif
    augroup CloseLoclistWindowGroup
        autocmd!
        autocmd QuitPre * if empty(&buftype) | lclose | endif
    augroup END
Plug 'wellle/targets.vim'
Plug 'wincent/terminus'
Plug 'zyedidia/literate.vim'

if !exists('g:started_by_firenvim')
    Plug 'vim-airline/vim-airline'
    let g:airline_powerline_fonts = 1
    let g:airline#extensions#tabline#enabled = 1
endif

if g:device ==# 'biglaptop'
    Plug '~/projects/hlas1/vim-hlas1'
        let g:hlas1_config_path = expand('~/code/projects/hlas1/vim-hlas1/config')
    Plug '~/projects/iprib/iprib0/vim-iprib'
    Plug '~/projects/jelly.vim'
    if has('nvim')
        Plug 'glacambre/firenvim', { 'do': { _ -> firenvim#install(0) } }
    endif
endif

if g:device ==# 'phone'
    Plug '~/hlas1/vim-hlas1'
        let g:hlas1_config_path = expand('~/hlas1/vim-hlas1/config')
    Plug '~/iprib/iprib0/vim-iprib'
    Plug '~/jelly.vim'
endif

call plug#end()
